{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Longest Continuous Increasing Subsequence"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: findLengthOfLCIS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #最长连续递增序列"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给定一个未经排序的整数数组，找到最长且<strong> 连续递增的子序列</strong>，并返回该序列的长度。</p>\n",
    "\n",
    "<p><strong>连续递增的子序列</strong> 可以由两个下标 <code>l</code> 和 <code>r</code>（<code>l < r</code>）确定，如果对于每个 <code>l <= i < r</code>，都有 <code>nums[i] < nums[i + 1]</code> ，那么子序列 <code>[nums[l], nums[l + 1], ..., nums[r - 1], nums[r]]</code> 就是连续递增子序列。</p>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [1,3,5,4,7]\n",
    "<strong>输出：</strong>3\n",
    "<strong>解释：</strong>最长连续递增序列是 [1,3,5], 长度为3。\n",
    "尽管 [1,3,5,7] 也是升序的子序列, 但它不是连续的，因为 5 和 7 在原数组里被 4 隔开。 \n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [2,2,2,2,2]\n",
    "<strong>输出：</strong>1\n",
    "<strong>解释：</strong>最长连续递增序列是 [2], 长度为1。\n",
    "</pre>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 <= nums.length <= 10<sup>4</sup></code></li>\n",
    "\t<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [longest-continuous-increasing-subsequence](https://leetcode.cn/problems/longest-continuous-increasing-subsequence/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [longest-continuous-increasing-subsequence](https://leetcode.cn/problems/longest-continuous-increasing-subsequence/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[1,3,5,4,7]', '[2,2,2,2,2]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        dp = [1 for _ in range(n)]\n",
    "        for i in range(1,n):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                dp[i] = dp[i-1] + 1\n",
    "        return max(dp)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        if len(set(nums)) == 1:\n",
    "            return 1\n",
    "        maxlen = 0\n",
    "        count = 1\n",
    "        for i in range(len(nums)-1):\n",
    "            if nums[i] < nums[i+1]:\n",
    "                count += 1\n",
    "            else:\n",
    "                count = 1\n",
    "            maxlen = max(maxlen,count)\n",
    "        return maxlen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        t, ans = 1, 0\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                t += 1\n",
    "            else:\n",
    "                ans = max(ans, t)\n",
    "                t = 1\n",
    "        return max(ans, t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        ans = 1\n",
    "        temp = 1\n",
    "        last = nums[0]\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > last:\n",
    "                temp += 1\n",
    "            else:\n",
    "                ans = max(ans, temp)\n",
    "                temp = 1\n",
    "            last = nums[i]\n",
    "        ans = max(ans, temp)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        List = nums\n",
    "        if len(List)<1:\n",
    "            return 0\n",
    "        if len(List) == 1:\n",
    "            return 1\n",
    "        num = list()\n",
    "        L = list()\n",
    "        # L.append([List[0]])\n",
    "        temp = [List[0]]\n",
    "        tempnum = 0\n",
    "        flag = 0\n",
    "        for i in range(1, len(List)):\n",
    "            flag += 1\n",
    "            if List[i] > List[i-1]:\n",
    "                temp.append(List[i])\n",
    "                tempnum += 1\n",
    "                if flag == i:\n",
    "                    L.append(temp)\n",
    "                    num.append(tempnum)\n",
    "                \n",
    "            else:\n",
    "                L.append(temp)\n",
    "                num.append(tempnum)\n",
    "                temp = list()\n",
    "                temp.append(List[i])\n",
    "                tempnum = 1\n",
    "        m = num.index(max(num))\n",
    "        return len(L[m])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        dp = [1]*len(nums)\n",
    "        res = 1\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                dp[i] = dp[i-1]+1\n",
    "            res = max(dp[i],res)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        if n == 1:\n",
    "            return 1\n",
    "        l, r = 0, 1\n",
    "        res = 1\n",
    "        while r < n:\n",
    "            if nums[r] > nums[r-1]:\n",
    "                r += 1\n",
    "            else:\n",
    "                res = max(res, r - l )\n",
    "                l = r\n",
    "                r = l + 1\n",
    "        res = max(res, r - l )\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        n=1\n",
    "        output=1\n",
    "        for i in range(len(nums)-1):\n",
    "            if nums[i+1]>nums[i]:\n",
    "                n+=1\n",
    "            else:\n",
    "                output=max(output,n)\n",
    "                n=1\n",
    "        output=max(output,n)\n",
    "        return output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        if n < 2:\n",
    "            return n\n",
    "        \n",
    "        max_len = 1\n",
    "        sub_len = 1\n",
    "        for i in range(n-1):\n",
    "            if nums[i+1] > nums[i]:\n",
    "                sub_len += 1\n",
    "                max_len = max(max_len, sub_len)\n",
    "            else:\n",
    "                sub_len = 1\n",
    "        return max_len"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        if len(nums) <= 0:\n",
    "            return 0\n",
    "        \n",
    "        res = 0\n",
    "        start = 0\n",
    "        for i in range(len(nums)):\n",
    "            if i > 0 and nums[i] <= nums[i - 1]:\n",
    "                start = i\n",
    "            \n",
    "            res = max(res, i - start + 1)\n",
    "\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        inc = ret = 1\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                inc += 1\n",
    "            else:\n",
    "                inc = 1\n",
    "            ret = max(inc, ret)\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        if len(nums) <= 1:\n",
    "            return 1\n",
    "        dp = [1] * len(nums)\n",
    "        for i in range(len(nums)-1):\n",
    "            if nums[i+1] > nums[i]:\n",
    "                dp[i+1] = dp[i] + 1\n",
    "        return max(dp)\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        if not nums:\n",
    "            return 0\n",
    "        n = len(nums)\n",
    "        dp = [1] * n\n",
    "        for i in range(1, n):\n",
    "            if nums[i] > nums[i - 1]:\n",
    "                dp[i] = dp[i - 1] + 1\n",
    "        return max(dp)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "\n",
    "        # 定义dp\n",
    "        dp = [1]*(len(nums))\n",
    "        \n",
    "        #遍历\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                dp[i] =dp[i-1] +1\n",
    "        return max(dp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        if len(nums)==1:\n",
    "            return 1\n",
    "        start, maxLength = 0, 1\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                length = i - start + 1\n",
    "                maxLength = max(maxLength,length)\n",
    "            else:\n",
    "                start = i\n",
    "        return maxLength\n",
    "\n",
    "                \n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        n=len(nums)\n",
    "        l=0\n",
    "        ans=1\n",
    "        p=0\n",
    "        while p<n-1:\n",
    "            while p<n-1 and nums[p+1]<=nums[p]:\n",
    "                p+=1\n",
    "                l+=1\n",
    "            while p<n-1 and nums[p+1]>nums[p]:\n",
    "                p+=1\n",
    "            ans=max(ans,p-l+1)\n",
    "            l=p\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        # dp[i]代表以nums[i]结尾的最长连续子序列, if nums[i] > nums[i-1]: dp[i] = dp[i-1] + 1 else: dp[i] = 1\n",
    "        dp = [1] * len(nums)\n",
    "        max_len = 1\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                dp[i] = dp[i-1] + 1\n",
    "            max_len = max(max_len, dp[i])\n",
    "        return max_len\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        dp=[1]*len(nums)\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                dp[i]=dp[i-1]+1\n",
    "        return max(dp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        if len(nums)<2: return 1\n",
    "        res = 1\n",
    "        count = 1\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                count+=1\n",
    "            else:\n",
    "                res = max(res, count)\n",
    "                count=1\n",
    "        return max(res,count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        i, j = 0, 1\n",
    "        ans = 1\n",
    "        while j < len(nums):\n",
    "            if nums[j-1]<nums[j]:\n",
    "                ans = max(ans, (j-i+1))\n",
    "            else:\n",
    "                i=j                \n",
    "            j += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        result=1\n",
    "        cur=1\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                cur+=1\n",
    "                result=max(result,cur)\n",
    "            else:\n",
    "                cur=1\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        max_len = 1\n",
    "        current_len = 1\n",
    "\n",
    "        for i in range(1,len(nums)):\n",
    "            current = nums[i]\n",
    "            if current > nums[i-1]:\n",
    "                current_len +=1\n",
    "                if current_len >= max_len:\n",
    "                    max_len = current_len\n",
    "            else:\n",
    "\n",
    "                current_len = 1\n",
    "        \n",
    "        return max_len\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        # # 使用DP解决，dp[i]表示以下标i为结尾的连续递增子序列的最大长度, 注意：表示的是以i为结尾的特征\n",
    "        # dp = [1]*len(nums)\n",
    "        # res = 1\n",
    "        # for i in range(1, len(nums)):\n",
    "        #     if nums[i] > nums[i-1]:\n",
    "        #         dp[i] = dp[i-1]+1\n",
    "        #     res = max(res, dp[i])\n",
    "        # return res\n",
    "\n",
    "        # dp[i]: 以nums[i]为结尾的连续递增子序列的最长长度\n",
    "        dp = [1] * len(nums)\n",
    "        maxlen = 1\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                dp[i] = dp[i-1]+1\n",
    "            maxlen = max(maxlen, dp[i])\n",
    "        return maxlen\n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        dp = [1] * len(nums)\n",
    "        res = 1\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                dp[i] = dp[i-1] + 1\n",
    "                res = max(res, dp[i])\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        j = 1\n",
    "        q = 0\n",
    "        if len(nums) <= 1:\n",
    "            return len(nums)\n",
    "        for i in range(len(nums)-1):\n",
    "            if nums[i+1] > nums[i]:\n",
    "                j += 1\n",
    "            else:\n",
    "                j = 1\n",
    "            q = max(q,j) \n",
    "        return q"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        \n",
    "        max_len=1\n",
    "        for i in range(len(nums)-1):\n",
    "            cn=1\n",
    "            j=i\n",
    "            while j<len(nums)-1:\n",
    "                if nums[j+1]>nums[j]:\n",
    "                    cn+=1\n",
    "                    j+=1\n",
    "                else:\n",
    "                    \n",
    "                    break\n",
    "            max_len=max(max_len,cn)\n",
    "        return max_len\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        cnt = 1\n",
    "        start = 0\n",
    "        n = len(nums)\n",
    "        for i in range(n):\n",
    "            if i and nums[i] <= nums[i-1]:\n",
    "                start = i\n",
    "            else:\n",
    "                cnt = max(i-start+1, cnt)\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        l = 0\n",
    "        r = 1\n",
    "        maxnum = 1\n",
    "        while r <= len(nums)-1 and l < r:\n",
    "            if nums[r] > nums[r-1]:\n",
    "                maxnum = max(maxnum, r-l+1)\n",
    "                r += 1\n",
    "            else:\n",
    "                l = r\n",
    "                r += 1\n",
    "        return maxnum\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        dp = [0 for i in range(len(nums))]\n",
    "        dp[0] = 1\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                dp[i] = dp[i-1]+1\n",
    "            else:\n",
    "                dp[i] = 1\n",
    "        return max(dp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        # dp[i]代表nums[i]的最长连续递增的子序列长度\n",
    "\n",
    "        # 初始化\n",
    "        dp = [1]*len(nums)\n",
    "\n",
    "        # 递推公式：dp[i]=dp[i-1]+1\n",
    "        # 遍历顺序：正序\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                dp[i]=dp[i-1]+1\n",
    "\n",
    "        #print(dp)\n",
    "        return max(dp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        left = right = 0\n",
    "        ans = 1\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i] <= nums[i-1]:\n",
    "                left = i\n",
    "\n",
    "            else:\n",
    "                right = i\n",
    "                ans = max(ans, right - left + 1)\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        l, r = 0, 1\n",
    "        ans = 1\n",
    "        tmp = 0\n",
    "        while r < len(nums):\n",
    "            if nums[r] <= nums[r-1]:\n",
    "                ans = max(ans, r-l)\n",
    "                l = r\n",
    "            r += 1\n",
    "        ans = max(ans, r-l)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        st = 0\n",
    "        for i in range(len(nums)):\n",
    "            if i > 0 and nums[i] <= nums[i - 1]:\n",
    "                st = i\n",
    "            res = max(res, i - st + 1)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        l, r, n = 0, 1, len(nums)\n",
    "        ans = 1\n",
    "        while r < n:\n",
    "            tmpAns = 1\n",
    "            while r < n and nums[r] > nums[r-1]:\n",
    "                tmpAns += 1\n",
    "                r += 1\n",
    "            # print(f\"l:{l}, r:{r}, tmpAns:{tmpAns}\")\n",
    "            ans = max(ans, tmpAns)\n",
    "            l = r\n",
    "            r = l + 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        if len(nums) == 1:\n",
    "            return 1\n",
    "        else:\n",
    "            l = []\n",
    "            l.append(nums[0])\n",
    "            max_len = 0\n",
    "            for i in range(1, len(nums)):\n",
    "                if nums[i] > nums[i-1]:\n",
    "                    l.append(nums[i])\n",
    "                else:\n",
    "                    l = []\n",
    "                    l.append(nums[i])\n",
    "                max_len = max(max_len, len(l))\n",
    "            return max_len\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        if not nums:\n",
    "            return 0\n",
    "\n",
    "        max_length = 1  # 初始最大长度为1\n",
    "        current_length = 1  # 当前连续递增子序列的长度\n",
    "\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > nums[i - 1]:\n",
    "                current_length += 1\n",
    "                max_length = max(max_length, current_length)\n",
    "            else:\n",
    "                current_length = 1\n",
    "\n",
    "        return max_length\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        maxlen =0 \n",
    "        l,r=0,0\n",
    "        while r<len(nums):\n",
    "            if nums[r-1]>=nums[r]:\n",
    "                l=r\n",
    "            r+=1\n",
    "            if r-l>=maxlen:\n",
    "                maxlen = r-l\n",
    "        return maxlen\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        result=1\n",
    "        count=1\n",
    "        for i in range(1,len(nums)):\n",
    "            if (nums[i]>nums[i-1]):\n",
    "                count+=1\n",
    "                result=max(result,count)\n",
    "            else:\n",
    "                count=1\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        max_increase_len = 1\n",
    "        increase_len = 1\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                increase_len += 1\n",
    "            else:\n",
    "                max_increase_len = max(max_increase_len, increase_len)\n",
    "                increase_len = 1\n",
    "        max_increase_len = max(max_increase_len, increase_len)\n",
    "        return max_increase_len"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        dp = [1] * len(nums)\n",
    "        result = 1\n",
    "\n",
    "        for i in range(1, len(nums)):\n",
    "            for j in (i-1, -1, -1):\n",
    "                if nums[j] >= nums[i]:\n",
    "                    break\n",
    "                dp[i] = max(dp[j]+1, dp[i])\n",
    "            result = max(result, dp[i])\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        dp = [1] * n\n",
    "        for i in range(1,n):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                dp[i] = dp[i-1]+1\n",
    "        \n",
    "        return max(dp)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        res=1\n",
    "        n=len(nums)\n",
    "        pre=1\n",
    "        for i in range(1,n):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                pre+=1\n",
    "            else:\n",
    "                res=max(res,pre)\n",
    "                pre=1\n",
    "        res=max(res,pre)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        dp = [1 for _ in range(n)]\n",
    "        for i in range(1, n):\n",
    "            if nums[i] > nums[i - 1]:\n",
    "                dp[i] = dp[i - 1] + 1\n",
    "\n",
    "        return max(dp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums) :\n",
    "        l = 0\n",
    "        r = 0\n",
    "        max = 0\n",
    "        if len(nums) == 1:\n",
    "            return 1\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                r = i\n",
    "            else:\n",
    "                r = i\n",
    "                l = i\n",
    "            if r - l + 1 > max:\n",
    "                max = r - l + 1\n",
    "        return max"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        n=len(nums)\n",
    "        k=1\n",
    "        x=[]\n",
    "        if n==1:\n",
    "            return 1\n",
    "        else:\n",
    "            for i in range(n-1):\n",
    "                if nums[i]<nums[i+1]:\n",
    "                    k=k+1\n",
    "                else:\n",
    "                    x.append(k)\n",
    "                    k=1\n",
    "            x.append(k)\n",
    "            if k==n:\n",
    "                return k\n",
    "            if k<n:\n",
    "                if x==[]:\n",
    "                    return 1\n",
    "                else:\n",
    "                    return max(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        N = len(nums)\n",
    "\n",
    "        l = 0\n",
    "        r = 0\n",
    "\n",
    "        ans = 0\n",
    "        while r<=N-1:\n",
    "            while r<N-1 and nums[r] < nums[r+1]:\n",
    "                r+=1\n",
    "            \n",
    "            tmp_res = r-l+1\n",
    "            ans = max(ans, tmp_res)\n",
    "\n",
    "            r+=1\n",
    "            l=r \n",
    "        return ans\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        if n == 0:\n",
    "            return 0\n",
    "        dp = [1] * n\n",
    "        res = 1\n",
    "        for i in range(1,n):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                dp[i] = dp[i-1] + 1\n",
    "                if dp[i] > res:\n",
    "                    res = dp[i]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        if n == 1:\n",
    "            return 1\n",
    "        dp = [1] * n\n",
    "        res = 0\n",
    "        for i in range(1,n):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                dp[i] = dp[i-1] + 1\n",
    "            res = max(res,dp[i])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        res=1\n",
    "        dp=[1]*len(nums)\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                dp[i]=dp[i-1]+1\n",
    "                res=max(res,dp[i])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        # patterns = [1] * len(nums)\n",
    "        # # ls = []\n",
    "        # for i in range(len(nums)):\n",
    "        #     ls = []\n",
    "        #     for j in range(i):\n",
    "        #         if nums[i] > nums[j]:\n",
    "        #             patterns[i] = max(patterns[j] + 1, patterns[i])\n",
    "        #             ls.append(nums[j])\n",
    "        #         else:\n",
    "        #             ls=[]\n",
    "                    \n",
    "        #     ls.append(nums[i])\n",
    "        #     print(ls)\n",
    "        # print(patterns)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        # # nums = [1,3,5,6,4,8,11,13,19,21,4,2]\n",
    "        # ls = []\n",
    "        # max_len = 0\n",
    "        # for i in range(len(nums)-1):\n",
    "        #     if nums[i] < nums[i+1]:\n",
    "        #         ls.append(nums[i+1])\n",
    "        #         if len(ls) > max_len:\n",
    "        #             max_len = len(ls)\n",
    "        #     else:\n",
    "        #         ls.insert(0, nums[i-len(ls)])\n",
    "        #         print(ls)\n",
    "        #         ls = []\n",
    "        # print(max_len+1)\n",
    "        # return max_len + 1\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        # res = []\n",
    "        # for i in range(len(nums)):\n",
    "        #     tmp = []\n",
    "        #     for j in range(i):\n",
    "        #         if nums[j] < nums[i]:\n",
    "        #             if tmp and sum(tmp[-1]) > nums[j]:\n",
    "        #                 tmp[-1] = tmp[-1] + [nums[j]]\n",
    "        #             else:\n",
    "        #                 tmp.append([nums[j]])\n",
    "        #     tmp.append([nums[i]])\n",
    "        #     # res.append(tmp)\n",
    "        #     res.append([x[0] for x in tmp if len(x) == 1])\n",
    "        # # print(res)\n",
    "\n",
    "        # print(max([len(x) for x in res]))\n",
    "        # return max([len(x) for x in res])\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        # nums_str = ''.join(map(str, nums))\n",
    "\n",
    "        # max_len = 0\n",
    "        # for i in range(len(nums)):\n",
    "        #     for j in range(i, len(nums)+1):\n",
    "        #         # print(nums[i:j+1])\n",
    "        #         sections = nums[i:j+1]\n",
    "        #         for k in range(len(sections)):\n",
    "        #             tmp=[]\n",
    "        #             for l in range(k):\n",
    "        #                 if sections[l] < sections[k]:\n",
    "        #                     if tmp and tmp[-1] < sections[l]:\n",
    "        #                         tmp.append(sections[l])\n",
    "        #                     elif not tmp:\n",
    "        #                         tmp.append(sections[l])\n",
    "        #         tmp.append(sections[k])\n",
    "        #         # print(tmp)\n",
    "        #         if len(tmp) > max_len and ''.join(map(str, tmp)) in nums_str:\n",
    "        #             max_len = len(tmp)\n",
    "        # print(max_len)\n",
    "        # return max_len\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        # # results = []\n",
    "        # max_len = 0\n",
    "        # for i in range(len(nums)):\n",
    "        #     left, right = i-1, i+1\n",
    "        #     tmp = [nums[i]]\n",
    "        #     while left >= 0:\n",
    "        #         if nums[left] < tmp[0]:\n",
    "        #             tmp.insert(0, nums[left])\n",
    "        #         else:\n",
    "        #             break\n",
    "        #         left -= 1\n",
    "            \n",
    "        #     while right < len(nums):\n",
    "        #         if nums[right] > tmp[-1]:\n",
    "        #             tmp.append(nums[right])\n",
    "        #         else:\n",
    "        #             break\n",
    "        #         right += 1\n",
    "            \n",
    "        #     if len(tmp) > max_len: max_len = len(tmp)\n",
    "        #     # if tmp not in results: results.append(tmp)\n",
    "\n",
    "        # # print(results)\n",
    "        # print(max_len)\n",
    "        # return max_len\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        # ls = nums\n",
    "        # results = []\n",
    "        # max_len = 0\n",
    "        # # for i in range(len(ls)):\n",
    "        # i = 0\n",
    "        # while i < len(ls):\n",
    "        #     left, right = i-1, i+1\n",
    "        #     tmp = [ls[i]]\n",
    "        #     # while left >= 0:\n",
    "        #     #     if ls[left] < tmp[0]:\n",
    "        #     #         tmp.insert(0, ls[left])\n",
    "        #     #     else:\n",
    "        #     #         break\n",
    "        #     #     left -= 1\n",
    "            \n",
    "        #     while right < len(ls):\n",
    "        #         if ls[right] > tmp[-1]:\n",
    "        #             tmp.append(ls[right])\n",
    "        #         else:\n",
    "        #             break\n",
    "        #         right += 1\n",
    "            \n",
    "        #     if len(tmp) > max_len: \n",
    "        #         max_len = len(tmp)\n",
    "        #         # i = right\n",
    "        #         print('right:', right)\n",
    "        #     # else:\n",
    "        #     #     i += 1\n",
    "\n",
    "        #     i = right\n",
    "                \n",
    "        #     # if tmp not in results: results.append(tmp)\n",
    "\n",
    "        # # print(results)\n",
    "        # print(max_len)\n",
    "        # return max_len\n",
    "\n",
    "\n",
    "\n",
    "        \n",
    "        ls = [] \n",
    "        max_len = 0\n",
    "        for i in range(len(nums)-1):\n",
    "            if nums[i] < nums[i+1]:\n",
    "                ls.append(nums[i+1])\n",
    "                if max_len < len(ls):\n",
    "                    max_len = len(ls)\n",
    "            else:\n",
    "                ls.insert(0, nums[i-len(ls)])\n",
    "                # print(ls)\n",
    "                ls = []\n",
    "        print(max_len + 1)\n",
    "        return max_len + 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        cnt, res = 1, 1\n",
    "\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > nums[i - 1]:\n",
    "                cnt += 1\n",
    "            else:\n",
    "                res = max(res, cnt)\n",
    "                cnt = 1\n",
    "\n",
    "        return max(res, cnt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        if len(nums)==0:\n",
    "            return 0\n",
    "        length=1#至少长度也为1\n",
    "        res=1\n",
    "        for i in range(len(nums)-1):\n",
    "            if nums[i+1]>nums[i]:\n",
    "                res+=1\n",
    "            else:\n",
    "                res=1#重新开始计数\n",
    "            length=max(length,res)\n",
    "        return length\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        dp = [1 for i in range(len(nums))]\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                dp[i] = dp[i-1] + 1\n",
    "        return max(dp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        if not nums:return 0\n",
    "        a = nums[0]\n",
    "        b = 1\n",
    "        res = []\n",
    "        for i in range(len(nums)-1):\n",
    "            if a < nums[i+1]:\n",
    "                b += 1\n",
    "                a = nums[i+1]\n",
    "            else:\n",
    "                res.append(b)\n",
    "                b = 1\n",
    "                a = nums[i+1]\n",
    "        res.append(b)\n",
    "        return max(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        dp = [1] * len(nums)\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > nums[i - 1]:\n",
    "                dp[i] = dp[i - 1] + 1\n",
    "        return max(dp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "\n",
    "        dp = [1] * len(nums)\n",
    "        maxLength = 1\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > nums[i - 1]:\n",
    "                dp[i] = dp[i - 1] + 1\n",
    "            if dp[i] > maxLength:\n",
    "                maxLength = dp[i]\n",
    "        return maxLength\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        count=1\n",
    "        ans=0\n",
    "        if len(nums)<=1:\n",
    "            return len(nums)\n",
    "\n",
    "        for i in range(len(nums)-1):\n",
    "            \n",
    "            if nums[i] < nums[i+1]:\n",
    "                count+=1\n",
    "            else:\n",
    "                count=1\n",
    "            ans=max(ans,count)\n",
    "            \n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        i=j=0\n",
    "        maxlen=1\n",
    "        while j<len(nums)-1:\n",
    "            if nums[j]<nums[j+1]:\n",
    "                j+=1\n",
    "            else:\n",
    "                maxlen=max(maxlen,j-i+1)\n",
    "                j+=1\n",
    "                i=j\n",
    "        return max(maxlen,j-i+1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        '''\n",
    "        res=1\n",
    "        start=0\n",
    "        for i in range(1,len(nums)):\n",
    "            if i>0 and nums[i]<=nums[i-1]:\n",
    "                start=i\n",
    "            res=max(res,i-start+1)\n",
    "        return res\n",
    "        '''\n",
    "        res=1\n",
    "        dp=[1]*len(nums)\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                dp[i]=dp[i-1]+1\n",
    "            if dp[i]>res:\n",
    "                res=dp[i]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        # patterns = [1] * len(nums)\n",
    "        # # ls = []\n",
    "        # for i in range(len(nums)):\n",
    "        #     ls = []\n",
    "        #     for j in range(i):\n",
    "        #         if nums[i] > nums[j]:\n",
    "        #             patterns[i] = max(patterns[j] + 1, patterns[i])\n",
    "        #             ls.append(nums[j])\n",
    "        #         else:\n",
    "        #             ls=[]\n",
    "                    \n",
    "        #     ls.append(nums[i])\n",
    "        #     print(ls)\n",
    "        # print(patterns)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        # # nums = [1,3,5,6,4,8,11,13,19,21,4,2]\n",
    "        # ls = []\n",
    "        # max_len = 0\n",
    "        # for i in range(len(nums)-1):\n",
    "        #     if nums[i] < nums[i+1]:\n",
    "        #         ls.append(nums[i+1])\n",
    "        #         if len(ls) > max_len:\n",
    "        #             max_len = len(ls)\n",
    "        #     else:\n",
    "        #         ls.insert(0, nums[i-len(ls)])\n",
    "        #         print(ls)\n",
    "        #         ls = []\n",
    "        # print(max_len+1)\n",
    "        # return max_len + 1\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        # res = []\n",
    "        # for i in range(len(nums)):\n",
    "        #     tmp = []\n",
    "        #     for j in range(i):\n",
    "        #         if nums[j] < nums[i]:\n",
    "        #             if tmp and sum(tmp[-1]) > nums[j]:\n",
    "        #                 tmp[-1] = tmp[-1] + [nums[j]]\n",
    "        #             else:\n",
    "        #                 tmp.append([nums[j]])\n",
    "        #     tmp.append([nums[i]])\n",
    "        #     # res.append(tmp)\n",
    "        #     res.append([x[0] for x in tmp if len(x) == 1])\n",
    "        # # print(res)\n",
    "\n",
    "        # print(max([len(x) for x in res]))\n",
    "        # return max([len(x) for x in res])\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        # nums_str = ''.join(map(str, nums))\n",
    "\n",
    "        # max_len = 0\n",
    "        # for i in range(len(nums)):\n",
    "        #     for j in range(i, len(nums)+1):\n",
    "        #         # print(nums[i:j+1])\n",
    "        #         sections = nums[i:j+1]\n",
    "        #         for k in range(len(sections)):\n",
    "        #             tmp=[]\n",
    "        #             for l in range(k):\n",
    "        #                 if sections[l] < sections[k]:\n",
    "        #                     if tmp and tmp[-1] < sections[l]:\n",
    "        #                         tmp.append(sections[l])\n",
    "        #                     elif not tmp:\n",
    "        #                         tmp.append(sections[l])\n",
    "        #         tmp.append(sections[k])\n",
    "        #         # print(tmp)\n",
    "        #         if len(tmp) > max_len and ''.join(map(str, tmp)) in nums_str:\n",
    "        #             max_len = len(tmp)\n",
    "        # print(max_len)\n",
    "        # return max_len\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        # # results = []\n",
    "        # max_len = 0\n",
    "        # for i in range(len(nums)):\n",
    "        #     left, right = i-1, i+1\n",
    "        #     tmp = [nums[i]]\n",
    "        #     while left >= 0:\n",
    "        #         if nums[left] < tmp[0]:\n",
    "        #             tmp.insert(0, nums[left])\n",
    "        #         else:\n",
    "        #             break\n",
    "        #         left -= 1\n",
    "            \n",
    "        #     while right < len(nums):\n",
    "        #         if nums[right] > tmp[-1]:\n",
    "        #             tmp.append(nums[right])\n",
    "        #         else:\n",
    "        #             break\n",
    "        #         right += 1\n",
    "            \n",
    "        #     if len(tmp) > max_len: max_len = len(tmp)\n",
    "        #     # if tmp not in results: results.append(tmp)\n",
    "\n",
    "        # # print(results)\n",
    "        # print(max_len)\n",
    "        # return max_len\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        ls = nums\n",
    "        results = []\n",
    "        max_len = 0\n",
    "        # for i in range(len(ls)):\n",
    "        i = 0\n",
    "        while i < len(ls):\n",
    "            left, right = i-1, i+1\n",
    "            tmp = [ls[i]]\n",
    "            # while left >= 0:\n",
    "            #     if ls[left] < tmp[0]:\n",
    "            #         tmp.insert(0, ls[left])\n",
    "            #     else:\n",
    "            #         break\n",
    "            #     left -= 1\n",
    "            \n",
    "            while right < len(ls):\n",
    "                if ls[right] > tmp[-1]:\n",
    "                    tmp.append(ls[right])\n",
    "                else:\n",
    "                    break\n",
    "                right += 1\n",
    "            \n",
    "            if len(tmp) > max_len: \n",
    "                max_len = len(tmp)\n",
    "                # i = right\n",
    "                print('right:', right)\n",
    "            # else:\n",
    "            #     i += 1\n",
    "\n",
    "            i = right\n",
    "                \n",
    "            # if tmp not in results: results.append(tmp)\n",
    "\n",
    "        # print(results)\n",
    "        print(max_len)\n",
    "        return max_len\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        if len(nums) <= 1:\n",
    "            return len(nums)\n",
    "        dp = [1] * len(nums)\n",
    "        result = 1\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > nums[i - 1]:\n",
    "                dp[i] = dp[i - 1] + 1\n",
    "            result = max(result, dp[i])  # 取长的子序列\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        res = [1] * len(nums)\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                res[i] = res[i-1] + 1\n",
    "        return max(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "\n",
    "        cur_len = 1\n",
    "        result = 1\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                cur_len += 1\n",
    "                result = max(result, cur_len)\n",
    "            else:\n",
    "                cur_len = 1\n",
    "        \n",
    "        return result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        # 分析：当前状态受前一状态影响，且遵守类似规则的求解问题，动态规划问题\n",
    "\n",
    "        # 截至到 i 的最长连续递增子序列的长度 cur\n",
    "\n",
    "        # 递推关系：如果满足当前元素递增 cur = cur+1\n",
    "\n",
    "        # 初始化：每个元素位置的初始递增长度都是 1 \n",
    "        length = len(nums)\n",
    "\n",
    "        # 利用其迭代过程，节省存储空间\n",
    "        cur = 1\n",
    "        result = 1\n",
    "\n",
    "        for i in range(1, length):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                cur = cur+1\n",
    "                result = max(result, cur)\n",
    "            else:\n",
    "                cur = 1\n",
    "\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        l = 0\n",
    "        ans = 1\n",
    "        for i in range( len(nums)):\n",
    "            r = i+1\n",
    "            if r < len(nums) and nums[r] > nums[i]:\n",
    "                ans = max(ans, r - l + 1)\n",
    "            else:\n",
    "                l =  r\n",
    "        return ans\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        \n",
    "        l, r, res = 0, 0, 0\n",
    "        while r < n:\n",
    "            if nums[r-1] >= nums[r] and r > 0:\n",
    "                l = r\n",
    "            r += 1\n",
    "            res = max(r-l, res)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        # 分析：当前状态受前一状态影响，且遵守类似规则的求解问题，动态规划问题\n",
    "\n",
    "        # 数组：截至到 i 的最长连续递增子序列的长度 dp[i]\n",
    "\n",
    "        # 递推关系：如果满足当前元素递增 dp[i] = max(dp[i], dp[i-1]+1)\n",
    "\n",
    "        # 初始化：每个元素位置的初始递增长度都是 1 \n",
    "        length = len(nums)\n",
    "\n",
    "        # 利用其迭代过程，节省存储空间\n",
    "        cur = 1\n",
    "        result = 1\n",
    "\n",
    "        for i in range(1, length):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                cur = cur+1\n",
    "                result = max(result, cur)\n",
    "            else:\n",
    "                cur = 1\n",
    "\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        res = 1\n",
    "        count = 1\n",
    "        for i in range(0, len(nums)-1):\n",
    "            if nums[i] < nums[i+1]:\n",
    "                count += 1\n",
    "            else:\n",
    "                count = 1\n",
    "            res = max(res,count)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        l = len(nums)\n",
    "        if l == 0:\n",
    "            return 0\n",
    "        dp = [1] * l\n",
    "        for i in range(1,l):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                dp[i] = dp[i-1]+1\n",
    "        return max(dp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        # 分析：当前状态受前一状态影响，且遵守类似规则的求解问题，动态规划问题\n",
    "\n",
    "        # 数组：截至到 i 的最长连续递增子序列的长度 dp[i]\n",
    "\n",
    "        # 递推关系：如果满足当前元素递增 dp[i] = max(dp[i], dp[i-1]+1)\n",
    "\n",
    "        # 初始化：每个元素位置的初始递增长度都是 1 \n",
    "        length = len(nums)\n",
    "\n",
    "        dp = [1] * length\n",
    "        result = 1\n",
    "\n",
    "        for i in range(1, length):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                dp[i] = dp[i-1]+1\n",
    "            result = max(result, dp[i])\n",
    "\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        res = 1\n",
    "        n = len(nums)\n",
    "        left, right = 0, 1\n",
    "        prev = nums[0]\n",
    "        \n",
    "\n",
    "        while right < n:\n",
    "            if nums[right] > prev:\n",
    "                res = max(res, right-left+1)\n",
    "                prev = nums[right]\n",
    "                right += 1\n",
    "            else:\n",
    "                left = right\n",
    "                right += 1\n",
    "                prev = nums[left]\n",
    "        return res \n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        res = 1\n",
    "        count = 1\n",
    "        for i in range(0, len(nums)-1):\n",
    "            if nums[i] < nums[i+1]:\n",
    "                count += 1\n",
    "            else:\n",
    "                count = 1\n",
    "            res = max(res,count)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        MaxCount,TmpCount = 1,1\n",
    "        low = 0\n",
    "        while low < len(nums)-1:\n",
    "            if nums[low+1] > nums[low]:\n",
    "                TmpCount += 1\n",
    "            else:\n",
    "                TmpCount = 1\n",
    "            if TmpCount > MaxCount:\n",
    "                MaxCount = TmpCount\n",
    "            low += 1\n",
    "        return MaxCount\n",
    "             "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        res=1\n",
    "        start=0\n",
    "        for i in range(1,len(nums)):\n",
    "            if i>0 and nums[i]<=nums[i-1]:\n",
    "                start=i\n",
    "            res=max(res,i-start+1)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        res = 1\n",
    "        count = 1\n",
    "        temp_count = 1\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i-1] < nums[i]:\n",
    "                temp_count += 1\n",
    "            elif nums[i-1] >= nums[i]:\n",
    "                temp_count = 1\n",
    "            \n",
    "            count = max(count,temp_count)\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "\n",
    "        dp = [1] * len(nums)\n",
    "\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                dp[i] = dp[i-1] + 1\n",
    "\n",
    "        return max(dp)\n",
    "\n",
    "\n",
    "        # cur_len = 1\n",
    "        # result = 1\n",
    "        # for i in range(1, len(nums)):\n",
    "        #     if nums[i] > nums[i-1]:\n",
    "        #         cur_len += 1\n",
    "        #         result = max(result, cur_len)\n",
    "        #     else:\n",
    "        #         cur_len = 1\n",
    "        \n",
    "        # return result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        if len(nums) == 1:\n",
    "            return 1\n",
    "        n = len(nums)\n",
    "        dp = [1] * n\n",
    "        result = 0\n",
    "        for i in range(n-1):\n",
    "            if nums[i+1] > nums[i]:\n",
    "                dp[i+1] = dp[i]+1\n",
    "            if dp[i+1] > result:\n",
    "                result = dp[i+1]\n",
    "        return result\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        dp = [1] * len(nums)\n",
    "        res = 1\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                dp[i] = dp[i-1] + 1\n",
    "                res = max(res, dp[i])\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findLengthOfLCIS(self, nums: List[int]) -> int:\n",
    "        count_res = 1\n",
    "        count = 1\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i-1] < nums[i]:\n",
    "                count += 1\n",
    "            elif nums[i-1] >= nums[i]:\n",
    "                count = 1\n",
    "            count_res = max(count_res,count)\n",
    "        return count_res"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
